import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
import { UserService } from './user.service';
import { UserDto } from './dto/create-user.dto';
import { AuthGuard } from 'src/gurad/auth/auth.guard';
import { getUserInfo } from 'src/utils/custom-decorators';
@UseGuards(AuthGuard)
@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  /**
   *查询用户
   */
  @Get('query')
  query(@Query() queryInfo) {
    return this.userService.query({
      ...queryInfo,
      currenPage: +queryInfo.currenPage,
      pageSize: +queryInfo.pageSize,
    });
  }
  /**
   * 删除用户
   */
  @Post('delete')
  delete(@Body() userDto: UserDto) {
    return this.userService.delete(userDto.id);
  }

  /**
   * 更新用户
   */
  @Post('update')
  update(@Body() userDto: UserDto) {
    return this.userService.update(userDto);
  }

  /**
   * 获取个人信息
  */
  @Get('userInfo')
  userInfo(@getUserInfo('id') id: number) {
    return this.userService.userInfo(+id)
  }

  /**
   * 获取个人文章列表
   * 
  */
  @Get('privateArticle')
  privateArticle(@getUserInfo('id') id: number) {
    return this.userService.privateArticle(+id)
  }
}
